package homework.day03;

import java.io.*;

public class Test02 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        File dir = new File(".");
        File[] subs = dir.listFiles((f)->f.getName().endsWith(".obj"));
        for (int i = 0;i<subs.length;i++){
            File sub = subs[i];
            FileInputStream fis = new FileInputStream(sub);
            ObjectInputStream ois = new ObjectInputStream(fis);
            Object obj = ois.readObject();
            if(obj instanceof User){
                User user = (User)obj;
                System.out.println(user);
            }
        }
    }
}
/*
    提示代码:
	需要用到的语句，尝试按照正确顺序将下列代码并放在main方法中完成需求，
	并在注释中标注每句话的作用，
	//获取当前目录下所有子项
    File dir = new File(".");

    //遍历subs中所有元素
    for(int i=0;i<subs.length;i++){

    }

    //定义一个文件过滤器subs，规律规则为以“.obj”结尾
    File[] subs = dir.listFiles((f)->f.getName().endsWith(".obj"));

    //使用文件输入流输入sub文件
    FileInputStream fis = new FileInputStream(sub);

    //从数组中获取每一个obj文件
    File sub = subs[i];//从数组中获取每一个obj文件

    //输出user
    System.out.println(user);

    //将ois流接到fis流上
    ObjectInputStream ois = new ObjectInputStream(fis);

    //强转obj为User
    User user = (User)obj;

    //反序列化
    Object obj = ois.readObject();

    //obj实现User接口
    if(obj instanceof User){

    }

 */